package ua.com.softway.date.benchmark;

import java.util.Random;

import ua.com.softway.date.Date;

/**
 * Original calendar-based:
 *   1000000 ops take 0m 5s 485ms
 *   0.005485ms per op
 *   
 * Modified calculation
 *   1000000 ops take 0m 0s 145ms
 *   0.0145ms per 100 op 
 */
public class TestAddDaysSpeed {
    public static void main(String[] args) {
        long begin = System.currentTimeMillis();
        
        Date date = Date.today();
//        java.util.Date jd = new java.util.Date();
        
        Random random = new Random(20);
        
        int ops = 1000000;
        
        for (int i = 0; i < ops; i ++) {
            date = date.daysAfter(10 - random.nextInt(20));
//            jd = new java.util.Date(jd.getTime() + (10 - random.nextInt(20)) * 24 * 60 * 60 * 1000);
        }

        long end = System.currentTimeMillis();
        
        System.out.println(ops + " ops take " + formatTime(end - begin));
        System.out.println((end - begin) * 100.0 / ops + "ms per 100 op");
    }

    private static String formatTime(long l) {
        long seconds = l / 1000 % 60;
        long minutes = l / 1000 / 60;
        long millis = l % 1000;
        
        return minutes  + "m " + seconds + "s " + millis + "ms";
    }
}
